home *** CD-ROM | disk | FTP | other *** search
- From: jamie@pro-net.co.uk (James Dickson)
- Newsgroups: comp.lang.c
- Subject: Re: File Display Program
- Date: Fri, 19 Apr 1996 10:01:25 GMT
- Message-ID: <317762d2.1345179@news.globalnet.co.uk>
- References: <4l6nrd$fr3@freenet-news.carleton.ca>
- X-Newsreader: Forte Agent .99d/32.182
- NNTP-Posting-Host: client8114.globalnet.co.uk
- Path: news.globalnet.co.uk!
-
- On 19 Apr 1996 00:47:41 GMT, aq436@FreeNet.Carleton.CA (Jerry Boyd)
- wrote:
-
- >
- >How would I write a program that would display the contents of
- >a file 20 lines at a time. At the end of each 20 lines, I need
- >it to wait for a character to be entered (in the form of "q" to
- >quit the display and any other character to continue with the
- >next 20 lines of the file)?
- >
- >
- >
- >--
- >
-
-
- Try something like:
-
- #include <stdio.h>
-
- main()
- {
-
- FILE *fpInput = fopen( "myfile","r" );
- int iCounter = 0;
- char szRecord[ 1024 ];
-
- if ( fpInput )
- {
- while( fgets( szRecord, sizeof( szRecord ), fpInput ) )
- {
- printf( "%s", szRecord );
- if ( (++iCounter) == 20 )
- {
- printf( "\nEnter Command:" );
- if ( getchar() == 'q' )
- exit(0);
- iCounter = 0;
- }
- }
- }
- else
- perror( "fopen" );
-
- }
-
-
- I haven't compiled this but it should give you some good pointers.
-
-
- James Dickson.
-